package com.vitabuybuy.tv.ui.cart

import android.os.Bundle
import androidx.core.os.bundleOf
import com.library.common.base.BaseActivity
import com.library.common.dto.MessageEvent
import com.vitabuybuy.tv.BR
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityPaySuccessBinding
import com.vitabuybuy.tv.ui.cart.viewmodel.ConfirmOrderViewModel
import com.vitabuybuy.tv.ui.mine.order.OrderDetailActivity
import com.vitabuybuy.tv.ui.mine.order.OrderListActivity
import com.vitabuybuy.tv.utils.EventCode
import kotlinx.android.synthetic.main.activity_pay_success.*
import org.greenrobot.eventbus.EventBus

class PaySuccessActivity : BaseActivity<ConfirmOrderViewModel, ActivityPaySuccessBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_pay_success

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, id: Int?, amount: Double?) {
            mContext.startActivity(
                bundleOf(Pair("id", id), Pair("amount", amount)),
                PaySuccessActivity::class.java
            )
        }
    }

    private var id :Int?= -1
    private var amount :Double?= 0.00
    override fun onGetBundle(bundle: Bundle?) {
        super.onGetBundle(bundle)
        id = bundle?.getInt("id")
        amount = bundle?.getDouble("amount")
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.pay))
        mBinding.setVariable(BR.amount, amount)
    }

    override fun eventHandling() {
        super.eventHandling()
        btnCheckOrder.setOnClickListener {
            EventBus.getDefault().post(MessageEvent(EventCode.jump_to_mine))
            EventBus.getDefault().post(MessageEvent(EventCode.update_order_list))
//            EventBus.getDefault().post(MessageEvent(EventCode.update_order_detail))
            OrderListActivity.openActivity(mContext, OrderListActivity.ALL)
            finish()
        }
    }
}
